+Mon Apr 22 19:24:29 2002 Kristian Rietveld <kris@gtk.org>
+
+ This commit adds stock icon functionality to GtkCellRendererPixbuf
+ which is totally cool.
+
+ * gtk/gtkcellrendererpixbuf.h: add some fields
+
+ * gtk/gtkcellrendererpixbuf.c: add finalize method, add some
+ properties, add some stock icon rendering code.
+
+ * demos/gtk-demo/stock_browser.c: modified to use the stock
+ icon stuff in the cellrendererpixbuf instead of its own stock icon
+ rendering code.
+
2002-04-21 Alexander Larsson <alla@lysator.liu.se>
* gdk/x11/gdkwindow-x11.c (gdk_window_reparent):
+Mon Apr 22 19:24:29 2002 Kristian Rietveld <kris@gtk.org>
+
+ This commit adds stock icon functionality to GtkCellRendererPixbuf
+ which is totally cool.
+
+ * gtk/gtkcellrendererpixbuf.h: add some fields
+
+ * gtk/gtkcellrendererpixbuf.c: add finalize method, add some
+ properties, add some stock icon rendering code.
+
+ * demos/gtk-demo/stock_browser.c: modified to use the stock
+ icon stuff in the cellrendererpixbuf instead of its own stock icon
+ rendering code.
+
2002-04-21 Alexander Larsson <alla@lysator.liu.se>
* gdk/x11/gdkwindow-x11.c (gdk_window_reparent):
+Mon Apr 22 19:24:29 2002 Kristian Rietveld <kris@gtk.org>
+
+ This commit adds stock icon functionality to GtkCellRendererPixbuf
+ which is totally cool.
+
+ * gtk/gtkcellrendererpixbuf.h: add some fields
+
+ * gtk/gtkcellrendererpixbuf.c: add finalize method, add some
+ properties, add some stock icon rendering code.
+
+ * demos/gtk-demo/stock_browser.c: modified to use the stock
+ icon stuff in the cellrendererpixbuf instead of its own stock icon
+ rendering code.
+
2002-04-21 Alexander Larsson <alla@lysator.liu.se>
* gdk/x11/gdkwindow-x11.c (gdk_window_reparent):
+Mon Apr 22 19:24:29 2002 Kristian Rietveld <kris@gtk.org>
+
+ This commit adds stock icon functionality to GtkCellRendererPixbuf
+ which is totally cool.
+
+ * gtk/gtkcellrendererpixbuf.h: add some fields
+
+ * gtk/gtkcellrendererpixbuf.c: add finalize method, add some
+ properties, add some stock icon rendering code.
+
+ * demos/gtk-demo/stock_browser.c: modified to use the stock
+ icon stuff in the cellrendererpixbuf instead of its own stock icon
+ rendering code.
+
2002-04-21 Alexander Larsson <alla@lysator.liu.se>
* gdk/x11/gdkwindow-x11.c (gdk_window_reparent):
+Mon Apr 22 19:24:29 2002 Kristian Rietveld <kris@gtk.org>
+
+ This commit adds stock icon functionality to GtkCellRendererPixbuf
+ which is totally cool.
+
+ * gtk/gtkcellrendererpixbuf.h: add some fields
+
+ * gtk/gtkcellrendererpixbuf.c: add finalize method, add some
+ properties, add some stock icon rendering code.
+
+ * demos/gtk-demo/stock_browser.c: modified to use the stock
+ icon stuff in the cellrendererpixbuf instead of its own stock icon
+ rendering code.
+
2002-04-21 Alexander Larsson <alla@lysator.liu.se>
* gdk/x11/gdkwindow-x11.c (gdk_window_reparent):
+Mon Apr 22 19:24:29 2002 Kristian Rietveld <kris@gtk.org>
+
+ This commit adds stock icon functionality to GtkCellRendererPixbuf
+ which is totally cool.
+
+ * gtk/gtkcellrendererpixbuf.h: add some fields
+
+ * gtk/gtkcellrendererpixbuf.c: add finalize method, add some
+ properties, add some stock icon rendering code.
+
+ * demos/gtk-demo/stock_browser.c: modified to use the stock
+ icon stuff in the cellrendererpixbuf instead of its own stock icon
+ rendering code.
+
2002-04-21 Alexander Larsson <alla@lysator.liu.se>
* gdk/x11/gdkwindow-x11.c (gdk_window_reparent):
GSList *ids;
GSList *tmp_list;
- store = gtk_list_store_new (1, STOCK_ITEM_INFO_TYPE);
+ store = gtk_list_store_new (2, STOCK_ITEM_INFO_TYPE, G_TYPE_STRING);
ids = gtk_stock_list_ids ();
ids = g_slist_sort (ids, (GCompareFunc) strcmp);
info.macro = id_to_macro (info.id);
gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter, 0, &info, -1);
+ gtk_list_store_set (store, &iter, 0, &info, 1, info.id, -1);
g_free (info.macro);
g_free (info.accel_str);
stock_item_info_free (info);
}
-static void
-macro_set_func_pixbuf (GtkTreeViewColumn *tree_column,
- GtkCellRenderer *cell,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- StockItemInfo *info;
-
- gtk_tree_model_get (model, iter,
- 0, &info,
- -1);
-
- g_object_set (GTK_CELL_RENDERER (cell),
- "pixbuf", info->small_icon,
- NULL);
-
- stock_item_info_free (info);
-}
-
static void
id_set_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
gtk_tree_view_column_pack_start (column,
cell_renderer,
FALSE);
- gtk_tree_view_column_set_cell_data_func (column, cell_renderer,
- macro_set_func_pixbuf, NULL, NULL);
+ gtk_tree_view_column_set_attributes (column, cell_renderer,
+ "stock_id", 1, NULL);
cell_renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column,
cell_renderer,
column);
cell_renderer = gtk_cell_renderer_text_new ();
-
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (treeview),
-1,
"Label",
NULL,
NULL);
+ cell_renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (treeview),
-1,
"Accel",
NULL,
NULL);
+ cell_renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (treeview),
-1,
"ID",
GParamSpec *pspec);
static void gtk_cell_renderer_pixbuf_init (GtkCellRendererPixbuf *celltext);
static void gtk_cell_renderer_pixbuf_class_init (GtkCellRendererPixbufClass *class);
+static void gtk_cell_renderer_pixbuf_finalize (GObject *object);
+static void gtk_cell_renderer_pixbuf_create_stock_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
+ GtkWidget *widget);
static void gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell,
GtkWidget *widget,
GdkRectangle *rectangle,
PROP_ZERO,
PROP_PIXBUF,
PROP_PIXBUF_EXPANDER_OPEN,
- PROP_PIXBUF_EXPANDER_CLOSED
+ PROP_PIXBUF_EXPANDER_CLOSED,
+ PROP_STOCK_ID,
+ PROP_STOCK_SIZE,
+ PROP_STOCK_DETAIL
};
+static gpointer parent_class;
+
GtkType
gtk_cell_renderer_pixbuf_get_type (void)
static void
gtk_cell_renderer_pixbuf_init (GtkCellRendererPixbuf *cellpixbuf)
{
+ cellpixbuf->stock_size = GTK_ICON_SIZE_MENU;
}
static void
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
+ parent_class = g_type_class_peek_parent (class);
+
+ object_class->finalize = gtk_cell_renderer_pixbuf_finalize;
+
object_class->get_property = gtk_cell_renderer_pixbuf_get_property;
object_class->set_property = gtk_cell_renderer_pixbuf_set_property;
GDK_TYPE_PIXBUF,
G_PARAM_READABLE |
G_PARAM_WRITABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_STOCK_ID,
+ g_param_spec_string ("stock_id",
+ _("Stock ID"),
+ _("The stock ID of the stock icon to render"),
+ NULL,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_STOCK_SIZE,
+ g_param_spec_enum ("stock_size",
+ _("Size"),
+ _("The size of the rendered icon"),
+ GTK_TYPE_ICON_SIZE,
+ GTK_ICON_SIZE_MENU,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_STOCK_DETAIL,
+ g_param_spec_string ("stock_detail",
+ _("Detail"),
+ _("Render detail to pass to the theme engine"),
+ NULL,
+ G_PARAM_READWRITE));
+
+}
+
+static void
+gtk_cell_renderer_pixbuf_finalize (GObject *object)
+{
+ GtkCellRendererPixbuf *cellpixbuf = GTK_CELL_RENDERER_PIXBUF (object);
+
+ if (cellpixbuf->pixbuf && cellpixbuf->stock_id)
+ g_object_unref (cellpixbuf->pixbuf);
+
+ if (cellpixbuf->stock_id)
+ g_free (cellpixbuf->stock_id);
+
+ if (cellpixbuf->stock_detail)
+ g_free (cellpixbuf->stock_detail);
+
+ (* G_OBJECT_CLASS (parent_class)->finalize) (object);
}
static void
g_value_set_object (value,
cellpixbuf->pixbuf_expander_closed ? G_OBJECT (cellpixbuf->pixbuf_expander_closed) : NULL);
break;
+ case PROP_STOCK_ID:
+ g_value_set_string (value, cellpixbuf->stock_id);
+ break;
+ case PROP_STOCK_SIZE:
+ g_value_set_enum (value, cellpixbuf->stock_size);
+ break;
+ case PROP_STOCK_DETAIL:
+ g_value_set_string (value, cellpixbuf->stock_detail);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
g_object_unref (G_OBJECT (cellpixbuf->pixbuf_expander_closed));
cellpixbuf->pixbuf_expander_closed = pixbuf;
break;
+ case PROP_STOCK_ID:
+ if (cellpixbuf->stock_id)
+ g_free (cellpixbuf->stock_id);
+ cellpixbuf->stock_id = g_strdup (g_value_get_string (value));
+ g_object_notify (G_OBJECT (object), "stock_id");
+ break;
+ case PROP_STOCK_SIZE:
+ cellpixbuf->stock_size = g_value_get_enum (value);
+ g_object_notify (G_OBJECT (object), "stock_size");
+ break;
+ case PROP_STOCK_DETAIL:
+ if (cellpixbuf->stock_detail)
+ g_free (cellpixbuf->stock_detail);
+ cellpixbuf->stock_detail = g_strdup (g_value_get_string (value));
+ g_object_notify (G_OBJECT (object), "stock_detail");
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
+
+ if (cellpixbuf->pixbuf && cellpixbuf->stock_id)
+ {
+ g_object_unref (cellpixbuf->pixbuf);
+ cellpixbuf->pixbuf = NULL;
+ }
}
/**
return GTK_CELL_RENDERER (gtk_type_new (gtk_cell_renderer_pixbuf_get_type ()));
}
+static void
+gtk_cell_renderer_pixbuf_create_stock_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
+ GtkWidget *widget)
+{
+ if (cellpixbuf->pixbuf)
+ g_object_unref (G_OBJECT (cellpixbuf->pixbuf));
+
+ cellpixbuf->pixbuf = gtk_widget_render_icon (widget,
+ cellpixbuf->stock_id,
+ cellpixbuf->stock_size,
+ cellpixbuf->stock_detail);
+}
+
static void
gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell,
GtkWidget *widget,
gint calc_width;
gint calc_height;
+ if (!cellpixbuf->pixbuf && cellpixbuf->stock_id)
+ gtk_cell_renderer_pixbuf_create_stock_pixbuf (cellpixbuf, widget);
+
if (cellpixbuf->pixbuf)
{
pixbuf_width = gdk_pixbuf_get_width (cellpixbuf->pixbuf);
GdkPixbuf *pixbuf;
GdkRectangle pix_rect;
GdkRectangle draw_rect;
+ gboolean stock_pixbuf = FALSE;
pixbuf = cellpixbuf->pixbuf;
if (cell->is_expander)
pixbuf = cellpixbuf->pixbuf_expander_closed;
}
- if (!pixbuf)
+ if (!pixbuf && !cellpixbuf->stock_id)
return;
+ else if (!pixbuf && cellpixbuf->stock_id)
+ stock_pixbuf = TRUE;
gtk_cell_renderer_pixbuf_get_size (cell, widget, cell_area,
&pix_rect.x,
&pix_rect.y,
&pix_rect.width,
&pix_rect.height);
+
+ if (stock_pixbuf)
+ pixbuf = cellpixbuf->pixbuf;
pix_rect.x += cell_area->x;
pix_rect.y += cell_area->y;
{
GtkCellRenderer parent;
+ /*< private >*/
GdkPixbuf *pixbuf;
GdkPixbuf *pixbuf_expander_open;
GdkPixbuf *pixbuf_expander_closed;
+
+ gchar *stock_id;
+ GtkIconSize stock_size;
+ gchar *stock_detail;
};
struct _GtkCellRendererPixbufClass